home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / src / ConfigFileSrc.lha / ConfigFileSrc12 / RexxLibrary / Funcs / New.c < prev    next >
Encoding:
Text File  |  1997-10-02  |  6.7 KB  |  264 lines

  1. /*
  2. **        $PROJECT: RexxConfigFile.library
  3. **        $FILE: New.c
  4. **        $DESCRIPTION: rxcf_New#?() functions
  5. **
  6. **        (C) Copyright 1997 Marcel Karas
  7. **             All Rights Reserved.
  8. */
  9.  
  10. IMPORT struct Library        *RexxSysBase;
  11. IMPORT struct Library        *CFBase;
  12.  
  13. /****** rexxconfigfile.library/cf_NewArgument ********************************
  14. *
  15. *   NAME
  16. *        cf_NewArgument -- Creates a new argument node.
  17. *
  18. *   SYNOPSIS
  19. *        ArgNode = cf_NewArgument(GrpNode,Name)
  20. *
  21. *        ARGNODE/N cf_NewArgument(GRPNODE/N/A,NAME/A)
  22. *
  23. *   FUNCTION
  24. *        This function creates a new argument node. The GrpNode must be a
  25. *        pointer to a group node. 
  26. *
  27. *   INPUTS
  28. *        GrpNode - The group node for add to. (!!! not NULL !!!)
  29. *        Name - The name of the new argument node.
  30. *
  31. *   RESULT
  32. *        ArgNode - The new argument node or NULL by failure.
  33. *
  34. *   EXAMPLE
  35. *        ...
  36. *        
  37. *        myArgNode = cf_NewArgument(myGrpNode,"ExampleArg")
  38. *        ...
  39. *
  40. *        In the CF file:
  41. *
  42. *        ...
  43. *        ExampleArg=
  44. *        ...
  45. *
  46. *   SEE ALSO
  47. *        cf_NewGroup(), cf_NewItem(), cf_NewArgItem()
  48. *
  49. ******************************************************************************
  50. *
  51. */
  52.  
  53. UWORD rxcf_NewArgument ( RX_FUNC_ARGS, CFGroup * GrpNode )
  54. {
  55.     CFArgument    * NewArgNode;
  56.  
  57.     if ( IsValidArg (RxMsg, 2) )
  58.     {
  59.         if ( NewArgNode = cf_NewArgument (GrpNode, RXARG2) )
  60.             *ResStr = CreateNumArgStrP (NewArgNode);
  61.         return (RC_OK);
  62.     }
  63.  
  64.     return (RXERR_INVALID_ARG);
  65. }
  66.  
  67. /****** rexxconfigfile.library/cf_NewGroup ***********************************
  68. *
  69. *   NAME
  70. *        cf_NewGroup -- Creates a new group node.
  71. *
  72. *   SYNOPSIS
  73. *        GrpNode = cf_NewGroup(Header,Name)
  74. *
  75. *        GRPNODE/N cf_NewGroup(HEADER/N/A,NAME/A)
  76. *
  77. *   FUNCTION
  78. *        This function creates a new group node. The Header must be a
  79. *        pointer to a CFHeader structure.
  80. *
  81. *   INPUTS
  82. *        Header - Pointer to the Header for add to. (!!! not NULL !!!)
  83. *        Name - Name of the new group node.
  84. *
  85. *   RESULT
  86. *        GrpNode - The new group node or NULL by failure.
  87. *
  88. *   EXAMPLE
  89. *        ...
  90. *        
  91. *        myGrpNode = cf_NewGroup(myHeader,"ExampleGroup")
  92. *        cf_NewArgument(myGrpNode,"ExampleArg")
  93. *        ...
  94. *
  95. *        In the CF file:
  96. *
  97. *        ...
  98. *        [ExampleGroup]
  99. *
  100. *        ExampleArg=
  101. *        ...
  102. *
  103. *   SEE ALSO
  104. *        cf_NewArgument(), cf_NewItem(), cf_NewArgItem()
  105. *
  106. ******************************************************************************
  107. *
  108. */
  109.  
  110. UWORD rxcf_NewGroup ( RX_FUNC_ARGS, CFHeader * Header )
  111. {
  112.     CFGroup    * NewGrpNode;
  113.  
  114.     if ( IsValidArg (RxMsg, 2) )
  115.     {
  116.         if ( NewGrpNode = cf_NewGroup (Header, RXARG2) )
  117.             *ResStr = CreateNumArgStrP (NewGrpNode);
  118.         return (RC_OK);
  119.     }
  120.  
  121.     return (RXERR_INVALID_ARG);
  122. }
  123.  
  124. /****** rexxconfigfile.library/cf_NewItem ************************************
  125. *
  126. *   NAME
  127. *        cf_NewItem -- Creates a new item node.
  128. *
  129. *   SYNOPSIS
  130. *        ItemNode = cf_NewItem(ArgNode,Contents [,Type] [,SpecialType])
  131. *
  132. *        ITEMNODE/N cf_NewItem(ARGNODE/N/A,CONTENTS/A,TYPE,STYPE)
  133. *
  134. *   FUNCTION
  135. *        This function creates a new item node. The ArgNode must be a
  136. *        pointer to a argument node.
  137. *
  138. *   INPUTS
  139. *        ArgNode - The argument node for add to. (!!! not NULL !!!)
  140. *        Contents - The contents of the new item node.
  141. *        Type - Type of the contents.
  142. *
  143. *           ITYP_STRING -- String type (Contents is a NULL-terminated string)
  144. *           ITYP_NUMBER -- Number type (Contents is long value e.g.
  145. *                          44253 or -23456)
  146. *           ITYP_BOOL   -- Bool type   (Contents is long value TRUE or
  147. *                          FALSE)
  148. *        SpecialType - Special types for cf_Write() or NULL for default.
  149. *
  150. *           ITYP_BOOL:
  151. *
  152. *             STYP_BOOL_YES  -- "YES/NO"
  153. *             STYP_BOOL_TRUE -- "TRUE/FALSE"
  154. *             STYP_BOOL_ON   -- "ON/OFF"
  155. *
  156. *           ITYP_NUMBER:
  157. *
  158. *             STYP_NUM_DEC   -- Decimal (e.g 24574)
  159. *             STYP_NUM_HEX   -- Hexdecimal (e.g. $fDe2)
  160. *             STYP_NUM_BIN   -- Binary (e.g. %10111)
  161. *
  162. *   RESULT
  163. *        ItemNode - The new group node or NULL by failure.
  164. *
  165. *   EXAMPLE
  166. *        ...
  167. *        
  168. *        myArgNode = cf_NewArgument(myGrpNode,"ExampleArg")
  169. *        cf_NewItem(myArgNode,"Foo Str",ITYP_STRING)
  170. *        cf_NewItem(myArgNode,5467,ITYP_NUMBER,STYP_NUM_DEC)
  171. *        cf_NewItem(myArgNode,35678,ITYP_NUMBER,STYP_NUM_HEX)
  172. *        cf_NewItem(myArgNode,23,CF_ITYP_NUMBER,STYP_NUM_BIN)
  173. *        cf_NewItem(myArgNode,FALSE,ITYP_BOOL,STYP_NUM_ON)
  174. *        cf_NewItem(myArgNode,TRUE,ITYP_BOOL,STYP_NUM_ON)
  175. *        cf_NewItem(myArgNode,TRUE,ITYP_BOOL,STYP_NUM_YES)
  176. *        ...
  177. *
  178. *        In the CF file:
  179. *
  180. *        ...
  181. *        ExampleArg="Foo Str",5467,$865E,%10111,OFF,ON,YES
  182. *        ...
  183. *
  184. *   SEE ALSO
  185. *        cf_NewArgument(), cf_NewGroup(), cf_Write(), cf_NewArgItem(),
  186. *        <libraries/configfile.h>
  187. *
  188. ******************************************************************************
  189. *
  190. */
  191.  
  192. UWORD rxcf_NewItem ( RX_FUNC_ARGS, CFArgument * ArgNode )
  193. {
  194.     RXCFItemConv  ItemConv;
  195.     CFItem        * ItemNode;
  196.  
  197.     if ( ConvItemStrings (RxMsg, &ItemConv, 2, 3, 4) )
  198.     {
  199.         if ( ItemNode = cf_NewItem(ArgNode, ItemConv.Contents, ItemConv.Type, ItemConv.SType) )
  200.             *ResStr = CreateNumArgStrP (ItemNode);
  201.         return (RC_OK);
  202.     }
  203.  
  204.     return (RXERR_INVALID_ARG);
  205. }
  206.  
  207. /****** rexxconfigfile.library/cf_NewArgItem *********************************
  208. *
  209. *   NAME
  210. *        cf_NewArgItem -- Creates a new argument node and a new item node.
  211. *
  212. *   SYNOPSIS
  213. *        ArgNode = cf_NewArgItem(GrpNode,Name,Contents [,Type][,SpecialType])
  214. *
  215. *        ARGNODE/N cf_NewArgItem(GRPNODE/N/A,NAME/A,CONTENTS/A,TYPE,STYPE)
  216. *
  217. *   FUNCTION
  218. *        This function creates a new argument node and a new item node. The
  219. *        GrpNode must be a pointer to a group node.
  220. *
  221. *   INPUTS
  222. *        GrpNode - The group node for add to. (!!! not NULL !!!)
  223. *        Name - The name of the new argument node.
  224. *        Contents - The contents of the new item node.
  225. *        Type - Type of the contents.
  226. *        SpecialType - Special types for cf_Write() or NULL for default.
  227. *
  228. *   RESULT
  229. *        ArgNode - The new argument node or NULL by failure.
  230. *
  231. *   EXAMPLE
  232. *        ...
  233. *        
  234. *        cf_NewArgItem(myGrpNode,"ExampleArg","FooStr",ITYP_STRING)
  235. *        ...
  236. *
  237. *        In the CF file:
  238. *
  239. *        ...
  240. *        ExampleArg="FooStr"
  241. *        ...
  242. *
  243. *   SEE ALSO
  244. *        cf_NewGroup(), cf_NewItem(), cf_NewArgument()
  245. *
  246. ******************************************************************************
  247. *
  248. */
  249.  
  250. UWORD rxcf_NewArgItem ( RX_FUNC_ARGS, CFGroup * GrpNode )
  251. {
  252.     RXCFItemConv  ItemConv;
  253.     CFArgument    * ArgNode;
  254.  
  255.     if ( IsValidArg (RxMsg, 2) && ConvItemStrings (RxMsg, &ItemConv, 3, 4, 5) )
  256.     {
  257.         if ( ArgNode = cf_NewArgItem(GrpNode, RXARG2, ItemConv.Contents, ItemConv.Type, ItemConv.SType) )
  258.             *ResStr = CreateNumArgStrP (ArgNode);
  259.         return (RC_OK);
  260.     }
  261.  
  262.     return (RXERR_INVALID_ARG);
  263. }
  264.